<?php require_once('../Connections/learnConn.php'); ?>
<?php
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "guru";
$MM_donotCheckaccess = "false";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && false) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "../index.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) 
  $MM_referrer .= "?" . $QUERY_STRING;
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
$colname_listNilai = $_GET['kode_kelas'];
$colname_listNilai2 = $_GET['kode_matpel'];
$colname_listNilai1 = $_GET['kode_sub_kelas'];
//SELECT s.nama, sk.nis, n.* FROM siswa s, nilai n WHERE kd_kelas=%s AND kd_kat_kelas=%s AND kd_matpel=%s
mysql_select_db($database_learnConn, $learnConn);
$query_listNilai = sprintf("SELECT * FROM nilai WHERE kd_kelas=%s AND kd_kat_kelas=%s AND kd_matpel=%s", 
						   GetSQLValueString($colname_listNilai, "int"),
						   GetSQLValueString($colname_listNilai1, "text"),
						   GetSQLValueString($colname_listNilai2, "text"));
$listNilai = mysql_query($query_listNilai, $learnConn) or die(mysql_error());
$row_listNilai = mysql_fetch_assoc($listNilai);
$totalRows_listNilai = mysql_num_rows($listNilai);

$query_listKelas = sprintf("SELECT * FROM kelas WHERE kelas=%s AND sub_kelas=%s", 
						   GetSQLValueString($colname_listNilai, "int"),
						   GetSQLValueString($colname_listNilai1, "text"));

$listKelas = mysql_query($query_listKelas, $learnConn) or die(mysql_error());
$row_listKelas = mysql_fetch_assoc($listKelas);
$totalRows_listKelas = mysql_num_rows($listKelas);

//echo $row_listKelas['kd_kelas'];
$query_listSiswa = sprintf("SELECT * FROM siswa_kelas WHERE kd_kelas=%s", 
						   GetSQLValueString($row_listKelas['kd_kelas'], "text"));

$listSiswa = mysql_query($query_listSiswa, $learnConn) or die(mysql_error());
$row_listSiswa = mysql_fetch_assoc($listSiswa);
$totalRows_listSiswa = mysql_num_rows($listSiswa);

$jk="";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Daftar Siswa</title>
<link href="../style/style.css" type="text/css" rel="stylesheet" />
<link href="../style/pro_drop_1.css" type="text/css" rel="stylesheet"/>
<script src="../style/stuHover.js" type="text/javascript"></script>
</head>

<body><center>
<table width="900" bgcolor="#FFFFFF">
	<?php
	include "topmenu_admin.php";
	?>
    <tr>
    	<td id="menu">
        <ul>
        	<li><a href="index.php">Home</a></li>
        	<li><a href="nilai.php">Daftar Kelas</a></li>
   	    <li><a href="jadwal.php">Jadwal</a></li>
        	<li><a href="passE.php">Ubah Password</a></li>
            <li><a href="../logout.php">Logout</a></li>
        </ul>
        </td>
    	<td id="konten"><a href="nilaiA.php?k=<?php echo $_GET['kode_kelas']; ?>&ks=<?php echo $_GET['kode_sub_kelas']; ?>&kp=<?php echo $colname_matpel = $_GET['kode_matpel']; ?>">Tambah Nilai</a><br />
        <table width="100%">
    	  <tr bgcolor="#CCCCCC">
    	    <td>NIS</td>
    	    <td>Nama</td>
    	    <td>JK</td>
    	    <td>UL1</td>
    	    <td>UL2</td>
    	    <td>UL3</td>
    	    <td>UL4</td>
    	    <td>UL5</td>
			<td>TGS1</td>
    	    <td>TGS2</td>
    	    <td>TGS3</td>
    	    <td>TGS4</td>
    	    <td>TGS5</td>
    	    <td>UTS</td>
    	    <td>UAS</td>
    	    <td>Nilai</td>
    	    <td>Aksi</td>
  	    </tr>
          <?php do { ?>
            <tr>
              <td><?php echo $row_listSiswa['nis']; ?></td>
              <td><?php 
			  $colname_siswa = $row_listSiswa['nis'];
				mysql_select_db($database_learnConn, $learnConn);
				$query_siswa = sprintf("SELECT nama, jenis_kelamin FROM siswa WHERE nis = %s", GetSQLValueString($colname_siswa, "text"));
				$siswa = mysql_query($query_siswa, $learnConn) or die(mysql_error());
				$row_siswa = mysql_fetch_assoc($siswa);
				$totalRows_siswa = mysql_num_rows($siswa);
				echo $row_siswa['nama'];
				$jk=$row_siswa['jenis_kelamin'];
				
				$query_nilaiE = sprintf("SELECT * FROM nilai WHERE nis = %s AND kd_kelas=%s AND kd_kat_kelas=%s AND kd_matpel=%s", 
						GetSQLValueString($colname_siswa, "text"),
					   GetSQLValueString($colname_listNilai, "text"),
                       GetSQLValueString($colname_listNilai1, "text"),
                       GetSQLValueString($colname_listNilai2, "text"));
				$nilaiE = mysql_query($query_nilaiE, $learnConn) or die(mysql_error());
				$row_nilaiE = mysql_fetch_assoc($nilaiE);
				$totalRows_nilaiE = mysql_num_rows($nilaiE);
				?></td>
              <td><?php echo $jk; ?></td>
			  <!--
              <td><?php //echo $row_listNilai['kd_kelas']; ?> - <?php //echo $row_listNilai['kd_kat_kelas']; ?></td>
              <td><?php //echo $row_listNilai['kd_matpel']; ?></td> -->
              <td><input type="text" name="ul1" value="<?php echo htmlentities($row_nilaiE['ul1'], ENT_COMPAT, 'utf-8'); ?>" onchange="hitung()" size="1" /></td>
              <td><input type="text" name="ul2" value="<?php echo htmlentities($row_nilaiE['ul2'], ENT_COMPAT, 'utf-8'); ?>" onchange="hitung()" size="1" /></td>
              <td><input type="text" name="ul3" value="<?php echo htmlentities($row_nilaiE['ul3'], ENT_COMPAT, 'utf-8'); ?>" onchange="hitung()" size="1" /></td>
              <td><input type="text" name="ul4" value="<?php echo htmlentities($row_nilaiE['ul4'], ENT_COMPAT, 'utf-8'); ?>" onchange="hitung()" size="1" /></td>
              <td><input type="text" name="ul5" value="<?php echo htmlentities($row_nilaiE['ul5'], ENT_COMPAT, 'utf-8'); ?>" onchange="hitung()" size="1" /></td>
              
			  <td><input type="text" name="tgs1" value="<?php echo htmlentities($row_nilaiE['tgs1'], ENT_COMPAT, 'utf-8'); ?>" onchange="hitung()" size="1" /></td>
			  <td><input type="text" name="tgs2" value="<?php echo htmlentities($row_nilaiE['tgs2'], ENT_COMPAT, 'utf-8'); ?>" onchange="hitung()" size="1" /></td>
			  <td><input type="text" name="tgs3" value="<?php echo htmlentities($row_nilaiE['tgs3'], ENT_COMPAT, 'utf-8'); ?>" onchange="hitung()" size="1" /></td>
			  <td><input type="text" name="tgs4" value="<?php echo htmlentities($row_nilaiE['tgs4'], ENT_COMPAT, 'utf-8'); ?>" onchange="hitung()" size="1" /></td>
			  <td><input type="text" name="tgs5" value="<?php echo htmlentities($row_nilaiE['tgs5'], ENT_COMPAT, 'utf-8'); ?>" onchange="hitung()" size="1" /></td>
			  
			  <td><input type="text" name="uts" value="<?php echo htmlentities($row_nilaiE['uts'], ENT_COMPAT, 'utf-8'); ?>" onchange="hitung()" size="1" /></td>
			  <td><input type="text" name="uas" value="<?php echo htmlentities($row_nilaiE['uas'], ENT_COMPAT, 'utf-8'); ?>" onchange="hitung()" size="1" /></td>
              <td><?php echo $row_nilaiE['nilai_akhir']; ?></td>
              <td>
              <a href="nilaiE.php?nis=<?php echo $row_listNilai['nis']; ?>&k=<?php echo $row_listNilai['kd_kelas']; ?>&ks=<?php echo $row_listNilai['kd_kat_kelas']; ?>&kp=<?php echo $colname_matpel = $_GET['kode_matpel']; ?>">Ubah Nilai</a>
			  
			  
              <a href="nilaiHapus.php?nis=<?php echo $row_listNilai['nis']; ?>&k=<?php echo $row_listNilai['kd_kelas']; ?>&ks=<?php echo $row_listNilai['kd_kat_kelas']; ?>&kp=<?php echo $colname_matpel = $_GET['kode_matpel']; ?>" onClick="return confirm('Apakah Anda benar-benar akan menghapus nilai?')">Hapus Nilai</a>
              </td>
            </tr>
            <?php } while ($row_listSiswa = mysql_fetch_assoc($listSiswa)); ?>
        </table></td>
    </tr>
    <tr>
    	<td colspan="2" id="footer">Copyright 2012</td>
    </tr>
    
</table></center>
</body>
</html>
<?php
//mysql_free_result($siswa);
//mysql_free_result($listNilai);
?>
